<template>
  <el-dialog
    append-to-body
    :close-on-click-modal="false"
    :before-close="crud.cancelCU"
    :visible="crud.status.cu > 0"
    :title="crud.status.title"
    width="500px"
  >
    <el-form
      ref="form"
      :model="form"
      :rules="rules"
      size="small"
      label-width="80px"
    >
      <el-form-item
        label="名称"
        prop="name">
        <el-input
          v-model="form.name"
          style="width: 370px;"
        />
      </el-form-item>

      <el-form-item label="渠道" prop="type">
        <el-select
          v-model="type"
          style="width: 178px"
          placeholder="请选择"
          @change="changeCity"
        >
          <el-option v-for="item in enabledTypeOptions"
                     :key="item.key"
                     :label="item.display_name"
                     :value="item.key"
          />
        </el-select>
      </el-form-item>
    </el-form>
    <div
      slot="footer"
      class="dialog-footer"
    >
      <el-button
        type="text"
        @click="crud.cancelCU"
      >
        取消
      </el-button>
      <el-button
        :loading="crud.status.cu === 2"
        type="primary"
        @click="crud.submitCU"
      >
        确认
      </el-button>
    </div>
  </el-dialog>
</template>

<script>
import CRUD, { form } from '@crud/crud'

const defaultForm = {
  id: null,
  name: '',
  type: ''
}
export default {
  mixins: [form(defaultForm)],
  props: {},
  data() {
    return {
      type: '',
      enabledTypeOptions: [
        { key: 1, display_name: '传统简历' },
        { key: 2, display_name: '广告简历' }
      ],
      rules: {
        name: [
          { required: true, message: '请输入渠道名称', trigger: 'blur' }
        ]
      }
    }
  },
  methods: {
    changeCity(value) {
      this.type = value
    },
    // 新增与编辑前做的操作
    [CRUD.HOOK.afterToCU](crud, form) {

    },
    // 新增前将多选的值设置为空
    [CRUD.HOOK.beforeToAdd]() {
      this.type = ''
    },
    // 初始化编辑时候的角色与岗位
    [CRUD.HOOK.beforeToEdit](crud, form) {
      this.type = form.type
    }
  }
}
</script>

<style rel="stylesheet/scss" lang="scss" scoped>
::v-deep .el-input-number .el-input__inner {
  text-align: left;
}
</style>
